package com.pphh.demo.gateway;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Please add description here.
 *
 * @author huangyinhuang
 * @date 2019/4/16
 */
@RestController
@RequestMapping("/api")
public class TestController {

    @RequestMapping(method = RequestMethod.GET, value = "/test")
    public String test(@RequestParam(required = false) Long time) {

        if (time != null && time > 0) {
            try {
                Thread.sleep(time);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        return "Hello,world";
    }

    @RequestMapping(method = RequestMethod.GET, value = "/echo")
    public String echo(@RequestParam(required = false) String userName) {
        return String.format("hello, %s. you have just sent a GET request", userName);
    }

    @RequestMapping(method = RequestMethod.POST, value = "/echo")
    public String echo2(@RequestParam(required = false) String userName) {
        return String.format("hello, %s. you have just sent a POST request", userName);
    }

}
